<!DOCTYPE html>



  


<html class="theme-next gemini use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.4" rel="stylesheet" type="text/css" />


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="配置中心," />










<meta name="description" content="搭建Apollo配置中心，并使用自带客户端来模拟配置实时生效的场景">
<meta name="keywords" content="配置中心">
<meta property="og:type" content="article">
<meta property="og:title" content="Apollo配置中心环境搭建">
<meta property="og:url" content="http://yoursite.com/2018/12/10/Apollo配置中心环境搭建/Apollo配置中心环境搭建/index.html">
<meta property="og:site_name" content="程序员乌托邦">
<meta property="og:description" content="搭建Apollo配置中心，并使用自带客户端来模拟配置实时生效的场景">
<meta property="og:locale" content="zh-Hans">
<meta property="og:updated_time" content="2018-12-10T03:21:37.140Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Apollo配置中心环境搭建">
<meta name="twitter:description" content="搭建Apollo配置中心，并使用自带客户端来模拟配置实时生效的场景">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Gemini',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://yoursite.com/2018/12/10/Apollo配置中心环境搭建/Apollo配置中心环境搭建/"/>





  <title>Apollo配置中心环境搭建 | 程序员乌托邦</title>
  








</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">程序员乌托邦</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle"></p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2018/12/10/Apollo配置中心环境搭建/Apollo配置中心环境搭建/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="Wolf、Heart">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="程序员乌托邦">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">Apollo配置中心环境搭建</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2018-12-10T11:16:07+08:00">
                2018-12-10
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/配置中心/" itemprop="url" rel="index">
                    <span itemprop="name">配置中心</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <h3 id="搭建Apollo配置中心，并使用自带客户端来模拟配置实时生效的场景"><a href="#搭建Apollo配置中心，并使用自带客户端来模拟配置实时生效的场景" class="headerlink" title="搭建Apollo配置中心，并使用自带客户端来模拟配置实时生效的场景"></a>搭建Apollo配置中心，并使用自带客户端来模拟配置实时生效的场景</h3><a id="more"></a>
<h1 id="一、下载Quick-Start安装包"><a href="#一、下载Quick-Start安装包" class="headerlink" title="一、下载Quick Start安装包"></a>一、下载Quick Start安装包</h1><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git clone https://github.com/nobodyiam/apollo-build-scripts.git</span><br></pre></td></tr></table></figure>
<h1 id="二、创建数据库"><a href="#二、创建数据库" class="headerlink" title="二、创建数据库"></a>二、创建数据库</h1><p>sql文件存放在刚才下载项目的sql文件夹下</p>
<ol>
<li><p>创建ApolloPortalDB数据库</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">source /your_local_path/sql/apolloportaldb.sql</span><br></pre></td></tr></table></figure>
</li>
<li><p>导入成功之后可以通过下面sql来验证</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">select `Id`, `AppId`, `Name` from ApolloPortalDB.App;</span><br></pre></td></tr></table></figure>
</li>
<li><p>创建ApolloConfigDB</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">source /your_local_path/sql/apolloconfigdb.sql</span><br></pre></td></tr></table></figure>
</li>
<li><p>导入成功后，可以通过执行以下sql语句来验证：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">select `NamespaceId`, `Key`, `Value`, `Comment` from ApolloConfigDB.Item;</span><br></pre></td></tr></table></figure>
</li>
</ol>
<h1 id="三、配置数据库连接信息"><a href="#三、配置数据库连接信息" class="headerlink" title="三、配置数据库连接信息"></a>三、配置数据库连接信息</h1><p>Apollo服务端需要知道如何连接到你前面创建的数据库，所以需要编辑demo.sh，修改ApolloPortalDB和ApolloConfigDB相关的数据库连接串信息。</p>
<p>==注意：== 填入的用户需要具备对ApolloPortalDB和ApolloConfigDB数据的读写权限。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">#apollo config db info</span><br><span class="line">apollo_config_db_url=jdbc:mysql://localhost:3306/ApolloConfigDB?characterEncoding=utf8</span><br><span class="line">apollo_config_db_username=用户名</span><br><span class="line">apollo_config_db_password=密码（如果没有密码，留空即可）</span><br><span class="line"></span><br><span class="line"># apollo portal db info</span><br><span class="line">apollo_portal_db_url=jdbc:mysql://localhost:3306/ApolloPortalDB?characterEncoding=utf8</span><br><span class="line">apollo_portal_db_username=用户名</span><br><span class="line">apollo_portal_db_password=密码（如果没有密码，留空即可）</span><br></pre></td></tr></table></figure>
<p>==注意：== 不要修改demo.sh的其它部分</p>
<h1 id="四、启动配置中心"><a href="#四、启动配置中心" class="headerlink" title="四、启动配置中心"></a>四、启动配置中心</h1><h2 id="4-1-确保端口为被占用"><a href="#4-1-确保端口为被占用" class="headerlink" title="4.1 确保端口为被占用"></a>4.1 确保端口为被占用</h2><p>Quick Start脚本会在本地启动3个服务，分别使用8070, 8080, 8090端口，请确保这3个端口当前没有被使用。</p>
<h2 id="4-2-执行启动脚本"><a href="#4-2-执行启动脚本" class="headerlink" title="4.2 执行启动脚本"></a>4.2 执行启动脚本</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">./demo.sh start</span><br></pre></td></tr></table></figure>
<p>当看到如下输出后，就说明启动成功了！<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">==== starting service ====</span><br><span class="line">Service logging file is ./service/apollo-service.log</span><br><span class="line">Started [1530]</span><br><span class="line">Waiting for config service startup.....</span><br><span class="line">Config service started. You may visit http://localhost:8080 for service status now!</span><br><span class="line">Waiting for admin service startup..</span><br><span class="line">Admin service started</span><br><span class="line">==== starting portal ====</span><br><span class="line">Portal logging file is ./portal/apollo-portal.log</span><br><span class="line">Started [1580]</span><br><span class="line">Waiting for portal startup....</span><br><span class="line">Portal started. You can visit http://localhost:8070 now!</span><br></pre></td></tr></table></figure></p>
<p>apollo配置中心启动后会启动3个端口</p>
<p>8070：apollo界面操作</p>
<p>8080：meta server地址、eureka访问地址</p>
<p>8081：apolloe-adminserver访问地址</p>
<p>访问<a href="http://localhost:8070" target="_blank" rel="noopener">http://localhost:8070</a> </p>
<p>用户名：apollo 密码：admin</p>
<h1 id="五、运行客户端程序"><a href="#五、运行客户端程序" class="headerlink" title="五、运行客户端程序"></a>五、运行客户端程序</h1><p>在之前下载的apollo-build-scripts项目下找到demo.sh，执行如下命令<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">./demo.sh client</span><br></pre></td></tr></table></figure></p>
<p>然后输入timeout，就以查看到该key对应的value</p>
<p>然后在apollo管理界面修改timeout的值，修改完成之后点击发布按钮，在客户端输入timeout就可以看到修改后的最新之</p>
<h1 id="六、搭建自己的客户端程序"><a href="#六、搭建自己的客户端程序" class="headerlink" title="六、搭建自己的客户端程序"></a>六、搭建自己的客户端程序</h1><p>使用Spring Boot来搭建客户端程序</p>

      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/配置中心/" rel="tag"># 配置中心</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2018/12/06/Hystrix使用/Hystrix使用/" rel="next" title="Hystrix使用">
                <i class="fa fa-chevron-left"></i> Hystrix使用
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2018/12/10/Apollo客户端搭建/Apollo客户端搭建/" rel="prev" title="Apollo客户端搭建">
                Apollo客户端搭建 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <p class="site-author-name" itemprop="name">Wolf、Heart</p>
              <p class="site-description motion-element" itemprop="description">主要用于分享平时学习的只是以及遇到的困难，帮助自己以及需要的人一起共同成长</p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives/">
              
                  <span class="site-state-item-count">45</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/categories/index.html">
                  <span class="site-state-item-count">14</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/tags/index.html">
                  <span class="site-state-item-count">13</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          

          

          
          

          
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-3"><a class="nav-link" href="#搭建Apollo配置中心，并使用自带客户端来模拟配置实时生效的场景"><span class="nav-number">1.</span> <span class="nav-text">搭建Apollo配置中心，并使用自带客户端来模拟配置实时生效的场景</span></a></li></ol></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#一、下载Quick-Start安装包"><span class="nav-number"></span> <span class="nav-text">一、下载Quick Start安装包</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#二、创建数据库"><span class="nav-number"></span> <span class="nav-text">二、创建数据库</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#三、配置数据库连接信息"><span class="nav-number"></span> <span class="nav-text">三、配置数据库连接信息</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#四、启动配置中心"><span class="nav-number"></span> <span class="nav-text">四、启动配置中心</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#4-1-确保端口为被占用"><span class="nav-number"></span> <span class="nav-text">4.1 确保端口为被占用</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#4-2-执行启动脚本"><span class="nav-number"></span> <span class="nav-text">4.2 执行启动脚本</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#五、运行客户端程序"><span class="nav-number"></span> <span class="nav-text">五、运行客户端程序</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#六、搭建自己的客户端程序"><span class="nav-number"></span> <span class="nav-text">六、搭建自己的客户端程序</span></a></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2018</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Wolf、Heart</span>

  
</div>


  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Gemini</a> v5.1.4</div>




        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  


  











  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  

  
  
    <script type="text/javascript" src="/lib/canvas-nest/canvas-nest.min.js"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.4"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.1.4"></script>



  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  












  





  

  

  

  
  

  

  

  

</body>
</html>
